<template>
	<!-- 车辆添加 -->
	<div>
		<div class="edit-top">
			相关人员信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">相关人员信息</div>
			<div class="edit-item" v-if="type == 0">
				<label>所属企业</label>
				<el-select v-model="enter_id" filterable placeholder="请选择">
					<el-option v-for="(item,index) in enter_list" :key="item.id" :label="item.enterpriseName" :value="item.id">
					</el-option>
				</el-select>
			</div>
			<div class="edit-item" >
				<label>姓名</label>
				<el-select v-model="client_id" :disabled="!is_select" filterable placeholder="请选择">
					<el-option v-for="(item,index) in client_list" :key="item.id" :label="item.chineseName" :value="item.id">
					</el-option>
				</el-select>
			</div>
			<div class="edit-item" >
				<label>角色</label>
				<el-select v-model="role_id"  filterable placeholder="请选择">
					<el-option v-for="(item,index) in role_list" :key="item.id" :label="item.roleName" :value="item.id">
					</el-option>
				</el-select>
			</div>
			
		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	let _this;
	export default {
		props: ['id','vin'],
		data() {
			return {
				enter_list:[],
				enter_id:'',
				type:'',
				
				is_select:false,
				
				client_list: [],
				client_id: '',
				
				role_list:[{roleName:'车辆产权人',id:0},{roleName:'车辆管理员',id:1},{roleName:'车辆使用人',id:2}],
				role_id:0,
				value: '',
				
				client_dict: '',
				dict: '',
				ordId:'',
				ord_list: [],
				
				info: {
					
					ownerIdcard: '',
					ownerType: '',
					ownerPhoneNum: '',
				}

			}
		},
		created() {
			_this = this;
		},
		watch: {
			enter_id(){
				this.is_select = true;
				this.get_client();
			}
		},
		mounted() {
			this.type = localStorage.getItem('type');
			if(this.type == 0){
				this.get_enter_list();
			}else{
				this.enter_id = localStorage.getItem('eId');
			}
		},
		methods: {
			get_enter_list(){
				this.$axios.post(this.$global.serverIp + 'jianeng-admin/sysEnterprise/findPage', {
						"limit": "10000",
						"page": "1",
					})
					.then(function(res) {
						if (res != '') {
							_this.enter_list = res.data.list;
							console.log(_this.enter_list);
						}
				
					})
				
			},
			get_client() {
				this.$axios.post(this.$global.serverIp + 'admin/sysClient/findPage', {
						"limit": "10000",
						"page": "1",
						"enterpriseId": _this.enter_id,
					})
					.then(function(res) {
						if (res != '') {
							_this.client_list = res.data.list;
						}
					})
			},
			save() {
				if (this.client_id == "") {
					this.$popup.open('姓名不能为空');
					return;
				}
				var s = {
					"vehicleId":this.id,
					"userId":this.client_id,
					"type":this.role_id,
				}

				this.$axios.post(this.$global.serverIp + 'vehicle/vehicleuser/save', s)
					.then(function(res) {
						if (res != '') {
							_this.success('添加成功');
						}
					})

			},
			success(content) {
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						_this.$emit("saveAddClient", 2);
					}
				});
			},
			cancel() {
				this.$emit("saveAddClient", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
